import pytest
from report.IHRMlogin import IhrmLogin
from common.assertTools import common_assert
from common.readJsonTools import read_json_file
from config import BASE_PATH


class TestIhrmLogin(object):


    def setup_class(self):
        self.ihrm = IhrmLogin()
        # 创建实例

    filename = BASE_PATH + "/data/loginData.json"
    # 调用readJsonTools的方法读取文件并换成元祖列表数据，需要加上目录位置
    data = read_json_file(filename)
    # 调用了之后读取里面数据换成元祖列表给到data变量
    @pytest.mark.parametrize("desc,req_body,status_code,success,code,message",data)
    def test_login_success(self,desc,req_body,status_code,success,code,message):
        # 通用测试方法，测试ihrm登录接口


        resp =self.ihrm.ihrmlogin_succses(req_body)
        print(desc,':',resp.json())

        # 断言
        common_assert(resp,status_code,success,code,message)
        # 调用封装通用断言的函数 传参是预期结果的参数
        # assert 200==resp.status_code
        # assert True is resp.json().get("success")
        # assert 10000 == resp.json().get("code")
        # assert "成功" in resp.json().get("message")


    # def test01_login_mobile_err(self):
    #
    #     req_data = {"mobile": "13815260002", "password": "123456"}
    #     resp =self.ihrm.ihrmlogin_succses(req_data)
    #     print('手机号未注册:',resp.json())
    #
    #     common_assert(resp,200,False,20001,"用户名或密码错误")
    #     # assert 200 == resp.status_code
    #     # assert False is resp.json().get("success")
    #     # assert 20001 == resp.json().get("code")
    #     # assert "用户名或密码错误" in resp.json().get("message")
    # #
    # # 断言
    #
    # #
    # def test02_login_pwd_err(self):
    #     # ihrm=IhrmLogin()
    #     req_data = {"mobile": "13800000002", "password": "12345678"}
    #     resp =self.ihrm.ihrmlogin_succses(req_data)
    #     print('密码错误:',resp.json())
    #
    #     common_assert(resp, 200, False, 20001, "用户名或密码错误")
    #     # assert 200 == resp.status_code
    #     # assert False is resp.json().get("success")
    #     # assert 20001 == resp.json().get("code")
    #     # assert "用户名或密码错误" in resp.json().get("message")
    #
    #
    # def test03_10_mobile(self):
    #     req_data = {"mobile": "1380000000", "password": "12345678"}
    #     resp = self.ihrm.ihrmlogin_succses(req_data)
    #     print('10位手机号码:', resp.json())
    #
    #     common_assert(resp, 200, False, 20001, "用户名或密码错误")
    #     # assert 200 == resp.status_code
    #     # assert False is resp.json().get("success")
    #     # assert 20001 == resp.json().get("code")
    #     # assert "用户名或密码错误" in resp.json().get("message")
    #
    # def test04_no_params(self):
    #     resp=self.ihrm.ihrmlogin_succses(None)
    #     print("无参：",resp.json())
    #
    #     common_assert(resp, 200, False, 99999, "系统繁忙")
    #
    #




